package com.qubuyer.core.utils

import android.app.Activity
import android.os.Build
import androidx.fragment.app.Fragment

/**
 * Author: linwg
 * Time: 2020/11/18 0018
 * Description:
 */
class PermissionUtil {
    companion object {
        /**
         * 权限是否被永久拒绝了
         */
        fun somePermissionPermanentlyDenied(activity: Activity, deniedList: List<String>): Boolean {
            if (Build.VERSION.SDK_INT < 23) {
                return true
            }
            for (per in deniedList) {
                if (!activity.shouldShowRequestPermissionRationale(per)) {
                    return true
                }
            }
            return false
        }

        /**
         * 权限是否被永久拒绝了
         */
        fun somePermissionPermanentlyDenied(fragment: android.app.Fragment, deniedList: List<String>): Boolean {
            if (Build.VERSION.SDK_INT < 23) {
                return true
            }
            for (per in deniedList) {
                if (!fragment.shouldShowRequestPermissionRationale(per)) {
                    return true
                }
            }
            return false
        }

        /**
         * 权限是否被永久拒绝了
         */
        fun somePermissionPermanentlyDenied(fragment: Fragment, deniedList: List<String>): Boolean {
            if (Build.VERSION.SDK_INT < 23) {
                return true
            }
            for (per in deniedList) {
                if (!fragment.shouldShowRequestPermissionRationale(per)) {
                    return true
                }
            }
            return false
        }
    }
}